import log from '@dfeidao/atom-nodejs/logger/log';
import msg from '@dfeidao/atom-nodejs/msg';
import { IncomingHttpHeaders } from 'http';

interface Message {
	cookie: {
		uk: string;
		[key: string]: string
	};
	urls: {
		base: string;
		origin: string;
		url: string;
	};
	query: {};
	params: {};
	headers: { cookie: string };
	usercode: string;
	userpw: string;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	console.log('===================', message);
	log('Service begin path:login/zj-000001/s001,1,action_id:' + action_id);
	const result = await msg.user_login(action_id, session_id, message.usercode, message.userpw);
	log('Service end path:login/zj-000001/s001,2,action_id:' + action_id);
	return {
		data: result,
		cookie: {
			sessionid: result.sessionID
		}
	};
}
